package com.eamois.ui.util;

import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import com.eamois.action.manual.EnsipAction;
import com.eamois.action.manual.EnsipBomAction;
import com.eamois.action.manual.EnsipStructureAction;
import com.eamois.domain.manual.Ensip;
import com.eamois.domain.manual.EnsipBom;
import com.eamois.pdmutil.pdmView.BomView;
import com.ufidaicon.icons.BrowserUfidaIcons;

public class BomColorTreeRenderer extends DefaultTreeCellRenderer{
	public BomColorTreeRenderer() {
		
	}
	
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean sel, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
				row, hasFocus);
		DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
		if (node.isRoot()) {
//			setIcon(new ImageIcon(com.eamois.icon.GetIcons.class
//					.getResource("equipment.png")));	
			setIcon(BrowserUfidaIcons.ICON_PRODUCT_DESIGONBOM);
		}
//			else {
//			setIcon(new ImageIcon(com.eamois.icon.GetIcons.class
//					.getResource("equipment_detail.png")));			
//		}
		if(node.getUserObject() instanceof BomView) {
			BomView bomView = (BomView) node.getUserObject();
			EnsipBomAction action = new EnsipBomAction();
			String partId = bomView.getPartId();
			String partVar = bomView.getPartVar();
			String chinaName = bomView.getChinaName();
			String parentId = bomView.getParentid();
			if(action.findBomByOther3(partId, partVar, chinaName).size() != 0){
				setForeground(Color.RED);
			}
			if("root".equals(parentId)){
//				setIcon(new ImageIcon(com.eamois.icon.GetIcons.class
//						.getResource("equipment.png")));	
				setIcon(BrowserUfidaIcons.ICON_PRODUCT_DESIGONBOM);
			}else{
//				setIcon(new ImageIcon(com.eamois.icon.GetIcons.class
//						.getResource("equipment_detail.png")));	
				setIcon(BrowserUfidaIcons.ICON_MATERIAL_ASSISTPART);
			}
		}
		return this;
	}
}
